package ruler.preferences;

import ruler.main.R;
import ruler.main.WifiGPSRulerApplication;

import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

public class RulerPreferencesActivity extends PreferenceActivity {

	private WifiGPSRulerApplication app;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preferences);
		app = (WifiGPSRulerApplication) getApplication();

		Preference customPref = (Preference) findPreference(getResources()
				.getString(R.string.pollAllApps));
		customPref
				.setOnPreferenceClickListener(new OnPreferenceClickListener() {
					public boolean onPreferenceClick(Preference preference) {
						// applyChanges();
						return true;
					}
				});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu_preferences, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.restartService:
			app.restartService();
			break;
		case R.id.startService:
			app.startService();
			break;
		case R.id.stopService:
			app.stopService();
			break;
		}
		return true;
	}

}